<template>
  <div class="pd-le-ri">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <el-icon :size="11"><user-filled /></el-icon> 角色申请
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div style="min-width: 800px; display: flex">
        <el-input
          v-model="userId"
          placeholder="查询用户ID"
          style="width: 200px;margin-right:20px"
        />
         <el-input
          v-model="mangerId"
          placeholder="查询管理ID"
          style="width: 200px;margin-right:20px"
        />
        <el-input
          v-model="roleType"
          placeholder="查询管理ID"
          style="width: 200px;margin-right:20px"
        />
        <div style="margin: 0 20px">
          <el-button type="primary" @click="clickBtn">搜索</el-button>
        </div>
      </div>
      <div style="margin: 20px 0 30px">
        <el-table
          :data="tableData.arr"
          border
          style="width: 100%"
          :stripe="true"
        >
          <el-table-column prop="campus_name" label="校区名" width="150" />
          <el-table-column
            prop="loginAddress"
            label="地址"
            width="100"
            align="center"
          ></el-table-column>
          <el-table-column prop="userName" label="用户名" width="120" />
          <el-table-column
            prop="id"
            label="管理ID"
            width="180"
          ></el-table-column>
          <el-table-column prop="userId" label="用户ID" width="180"></el-table-column>
          <el-table-column prop="roleType" label="角色类型" width="100"></el-table-column>
          <el-table-column prop="balance" label="余额" width="100"></el-table-column>
          <el-table-column prop="finishOrderSum" label="完成订单数" width="100"></el-table-column>
          <el-table-column label="操作" align="center">
            <template v-slot="scope">
              <el-button
                size="small"
                v-if="scope.row.status == 0"
                @click="closeAdmin(scope.row.userId)"
                >禁用</el-button
              >
              <el-button
                type="success"
                size="small"
                v-if="scope.row.status == 1"
                @click="openAdmin(scope.row.userId)"
                >开启</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div style="margin-bottom: 10px">
        <div class="demo-pagination-block">
          <el-pagination
            :page-size="10"
            layout="total, prev, pager, next, jumper"
            :total="total"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, onMounted } from "vue";
import { getUesrList,editUser } from '../../http/user/user'
import { UserFilled } from "@element-plus/icons";

export default defineComponent({
  components: {
    UserFilled,
  },
  setup() {

    let tableData = reactive({
      arr: [],
    });
    let total = ref();
    let page: number = 1;
    let mangerId = ref("");
    let userId = ref("")
    let roleType = ref("")
    let campusName = ref("")
    const dialogVisible = ref(false);

    onMounted(() => {
      // getList();
    });

    const getList = async () => {
      const res: any = await getUesrList({});
      tableData.arr = res.data.records;
      total.value = res.data.total;
    };

    const handleCurrentChange = (e: number) => {
      page = e;
    };

    const clickBtn = () => {
      getList();
    };

    const openAdmin = async (e: any) => {
      let changge = {
        staffId: e,
        status: 1,
      };
      const res: any = await editUser();
      getList();
    };

    const closeAdmin = async (e: any) => {
      let changge = {
        staffId: e,
        status: 0,
      };
      const res: any = await editUser();
      getList();
    };

    return {
      mangerId,
      tableData,
      total,
      userId,
      roleType,
      dialogVisible,
      handleCurrentChange,
      clickBtn,
      openAdmin,
      closeAdmin,
    };
  },
});
</script>

<style scoped>
</style>
